//
//  UIImage+CircleImage.m
//  TaShuo
//
//  Created by N-X on 2018/3/22.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "UIImage+CircleImage.h"

@implementation UIImage (CircleImage)
+ (UIImage *)circleImage:(UIImage *)image
{
    CGFloat imageWH = image.size.width;
    //圆环的宽度
    CGFloat borderW = 3;
    // 大圆环的直径
    CGFloat circleWH = imageWH + borderW * 2;
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(circleWH, circleWH), NO, 0.0);
    UIBezierPath * path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, circleWH, circleWH)];
    [[UIColor whiteColor] set];
    [path fill];
    UIBezierPath * clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, imageWH, imageWH)];
    [clipPath addClip];
    [image drawAtPoint:CGPointMake(borderW, borderW)];
    UIImage * clipImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return clipImage;
}
@end
